@extends('admin.layouts.app')
@section('css')
 
   <link href="{{asset('assets/plugins/dropzone/dropzone.css')}}" rel="stylesheet" type="text/css" />
  

@endsection
@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">平台管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="#">系统</a></li>
                                    <li><a href="{{url('zadmin/type')}}">商品管理</a></li>
                                    <li class="active">添加商品</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                            <h2 class="m-t-0 header-title">添加商品</h2>
                            <hr/>
                             
                              @include('admin.common.error')
                      
                              
                      <form class="form-horizontal" role="form" action="{{url('zadmin/product/save')}}" method="post">  			<div class="row">
			                        	<div class="col-md-12">
                                  
                     

                  <div class="form-group col-md-6">
                      <label class="col-md-3 control-label">商品名</label>
                      <div class="col-md-9">
                          <input type="text" class="form-control" name="name" required="" value="" >
                      </div>
                  </div>
                  <div class="form-group col-md-6">
                      <label class="col-md-3 control-label">商品类别</label>
                      <div class="col-md-9">
                          <select  class="form-control" name="cate_id" required="" >
                            <option value="">请选择</option>
                            @foreach($cates as $cate)
                            <option value="{{$cate->id}}">{{$cate->name}}</option>
                            @endforeach
                          </select>
                      </div>
                  </div>
                  <div class="form-group col-md-6">
                        <label class="col-md-3 control-label">市场价</label>
                        <div class="col-md-9">
                            <input type="text" class="form-control" name="market_price" required="" value="" >
                        </div>
                  </div>

                  <div class="form-group col-md-6">
                      <label class="col-md-3 control-label">平台价</label>
                      <div class="col-md-9">
                          <input type="text" class="form-control" name="price" required="" value="" >
                      </div>
                  </div>
                  <div class="form-group col-md-6">
                      <label class="col-md-3 control-label">使用公里</label>
                      <div class="col-md-9">
                          <input type="text" class="form-control" name="hours" required="" value="50" >
                      </div>
                  </div>
                  <div class="form-group col-md-6">
                      <label class="col-md-3 control-label">使用时间</label>
                      <div class="col-md-9">
                          <input type="text" class="form-control" name="miles" required="" value="5" >
                      </div>
                  </div>

                   


                  <div class="form-group col-md-12">
                    <label class="control-label col-sm-2">上传图片</label>
                    <div class="col-sm-10">     
                      <div id="filelist"></div>

                      <div class="piclist"></div>
                                                                   
                    <button class="btn" type="button" id="pickfiles">选择图片</button>
                  </div>                          
                                                 
                </div>
                <div id="container"></div>
                  
                                              

                                              

                                              
                                </div>
			                        	
			                        </div>

                             
      
                         
                           
            <hr/>                
            <div class="row">
            
                <div class="col-md-12">
                  <table  class="table no-footer" id="car">
                    <thead>
                      <tr>
                      
                    
                      <th class="">车辆品牌</th>
                      <th>车系</th>
                      
                      <th class="">数量</th>
                      <th>是否头车</th>
                      <th class="">操作</th>
                    </tr>
                    </thead>
          <tbody class="caritem">
            <tr>            
              
              <td>
                  <select  class="form-control car_brand_id" placeholder="" name="car_brand_id[]">
                    <option value="">请选择</option>
                    @foreach($brands as $b)
                    <option value="{{$b->id}}">{{$b->name}}</option>
                    @endforeach
                  </select>
              </td>
              <td>
                  <select  class="form-control car_serie_id"  name="car_serie_id[]" >
                  </select>
              </td>
              <td>
                  <input class="form-control" name="num[]" />

              </td>
              <td>
                <select  name="is_headcar[]" class="form-control" >
                  <option value="">请选择</option>
                  <option value="1">头</option>
                  <option value="2">跟</option>
              </td>
              
              <td width="100">
                  <button type="button" class="btn btn-sm btn-primary btn-add"><i class="md md-add"></i></button>
                  <button type="button" class="btn btn-sm btn-danger btn-remove"><i class="md md-remove"></i></button>
              </td>
            </tr>
          </tbody>
        </table>                  

                                           
      </div>                                
           </div>



           <div class="form-group text-center">
                                                  
                                                  <button type="submit" class="btn btn-info waves-effect waves-light">保存</button>
                                              </div>
                                              
                                              
                             {{csrf_field()}}

                             <input name="pics" id="pics" type="hidden" />  
                                          </form>
        
			                        
                        			
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
    @section('modal')        
     
    @endsection        
       

           



    
@section('js')
 <script type="text/javascript" src="/js/plupload/plupload.full.min.js"></script>
<script type="text/javascript">
  $(document).on('click','.btn-add',function(){
            var tr = $('.caritem tr').eq(0).clone();

            $('#car').append(tr);
            console.info(tr);
  });
       
  $(document).on('click','.btn-remove',function(){
    $(this).parents('tr').remove();
  })


  var pics = '';
  var uploader = new plupload.Uploader({
      runtimes : 'html5,flash,silverlight,html4',
      browse_button : 'pickfiles', // you can pass an id...
      container: document.getElementById('container'), // ... or DOM Element itself
      url : '/upload.php',
      flash_swf_url : '../js/Moxie.swf',
      silverlight_xap_url : '../js/Moxie.xap',
              
              filters : {
                max_file_size : '10mb',
                mime_types: [
                  {title : "Image files", extensions : "jpg,gif,png"}
                  
                ]
              },

              init: {
                PostInit: function() {
                  $('#filelist').html('');

                  
                },

                FilesAdded: function(up, files) {
                  plupload.each(files, function(file) {
                    $('#filelist').html('<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>');
                     uploader.start();
                     return false;
                  });
                },

               

                 FileUploaded: function(up, file, info) {
                            // Called when file has finished uploading
                              var rs =  JSON.parse(info.response);
                              if(rs.status){
                                var str = '<img style="padding:5px" src="'+rs.data+'" width="100">';
                                $('.piclist').append(str);
                                pics += rs.data+',';
                                $('#pics').val(pics);
                              }
                              console.info(rs);
                              
                },  
              }
            });

uploader.init();


$(document).on('change','.car_brand_id',function(){

    var _this    = $(this);
    var brand_id = _this.val();
    var url = "{{url('api/car-series')}}";
       
     $.get(url,{'brand_id':brand_id},function(rs){
            if(rs.status==true) {
                var service = _this.parents('tr').find('.car_serie_id');
                service.empty();
                var opt = '';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'">'+v.name+'</option>'; 
                });
                 service.append(opt);
                
            }
        })
 });
</script>        
@endsection
    
